package com.zjut.azhen.DBDesign.controllers.admin;

import com.zjut.azhen.DBDesign.bean.RespBean;
import com.zjut.azhen.DBDesign.bean.Students;
import com.zjut.azhen.DBDesign.bean.Teacher;
import com.zjut.azhen.DBDesign.service.StudentsService;
import com.zjut.azhen.DBDesign.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author asus
 */
@RestController
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    TeacherService teacherService;
    @GetMapping("/")
    public RespBean getAll(){
        return RespBean.ok("success",teacherService.getAll());
    }


    @PutMapping("/")

    public RespBean updateTeacher(@RequestBody Teacher teacher){
        if(teacherService.updateTeacherById(teacher)==1){
            return RespBean.ok("success");
        }
        return RespBean.error("fail update");
    }


    @PostMapping("/")
    public RespBean intertTeacher(@RequestBody Teacher teacher){
        if(teacherService.insertTeacher(teacher)==1) {
            return RespBean.ok("success");
        }
        return RespBean.error("insert failed");
    }
    @DeleteMapping("/{id}")
    public RespBean deleteTeacherById(@PathVariable String id){
        if(teacherService.deleteTeacherById(id)==1) {
            return RespBean.ok("success");
        }
        return RespBean.error("insert failed");
    }
    @PutMapping("/score")
    public RespBean insertTeacher(@RequestParam("sno") String sno,
                               @RequestParam("cno") String cno,
                               @RequestParam("score") Float score){
        if(teacherService.insertScore(sno,cno,score)==1){
            return RespBean.ok("success");
        }
        return RespBean.error("fail update");
    }
}
